package practice11;

import java.util.Iterator;
import java.util.List;

public class Teacher extends  Person{
    private List<Klass> classes;

    public Teacher(int i, String name, int age) {
        super(i,name,age);
    }

    public Teacher(int i, String name, Integer age, List<Klass> classes) {
        super(i, name, age);
        this.classes = classes;
    }

    public Teacher(String name, Integer age, List<Klass> classes) {
        super(name, age);
        this.classes = classes;
    }

    public List<Klass> getClasses() {
        return classes;
    }

    public void setClasses(List<Klass> classes) {
        this.classes = classes;
    }

    @Override
    public String introduce(){
        StringBuilder words=new StringBuilder(super.introduce()+" I am a Teacher. I teach Class");
        if(this.classes==null){
            return super.introduce()+" I am a Teacher. I teach No Class.";
        }
        Iterator iterator=classes.iterator();
        while(iterator.hasNext()){
            Klass klass = (Klass) iterator.next();
            words.append(" "+klass.getNumber()+",");
        }
        char[] chars = words.toString().toCharArray();
        chars[chars.length-1]='.';
        words=new StringBuilder(new String(chars));
        return words.toString();
    }

    public boolean isTeaching(Student student) {
        return getClasses().contains(student.getKlass());
    }
    public String introduceWith(Student student){
        if(classes.contains(student.getKlass())){
            return super.introduce()+" I am a Teacher. I teach "+student.getName()+".";
        }
        return  super.introduce()+" I am a Teacher. I don't teach "+student.getName()+".";
    }
}
